package kr.pe.osdev.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.pe.osdev.domain.User;
import kr.pe.osdev.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    
    @Autowired
    UserService userService = null;
    
    @RequestMapping(method=RequestMethod.POST)
    public String authenticate(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("AUTH");
        User user = new User();
        user.setUserId("beta1");
        user.setPasswd("beta1");
        
        userService.authenticate(user);
        
        ModelAndView mv = new ModelAndView();
        mv.setViewName("authenticate");
        
        return request.getParameter("test");
    }
    
    @RequestMapping
    public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("LOGIN");
        return new ModelAndView("user/login", "message", "Fuck");
    }
    
    @RequestMapping("/user/list.html")
    public ModelMap list(ModelMap model) {
        model.addAttribute("list", userService.findList());
        
        return model;
    }    
}